<html>
<head><meta charset="utf-8"><title>Semicolons after `return` spoils type inference · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Semicolons.20after.20.60return.60.20spoils.20type.20inference.html">Semicolons after `return` spoils type inference</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="174231112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Semicolons%20after%20%60return%60%20spoils%20type%20inference/near/174231112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Semicolons.20after.20.60return.60.20spoils.20type.20inference.html#174231112">(Aug 27 2019 at 13:54)</a>:</h4>
<p>I've just noticed that the type is inferred incorrectly when a semicolon added to the <code>return</code> keyword.</p>
<p>This works fine with the PR that fixes Never inference </p>
<div class="codehilite"><pre><span></span>let i = if true {
        2.0
    } else {
        return
    };
</pre></div>


<p>inferring <code>f64</code> for <code>i</code> but if you add any number of semicolons after <code>return</code>,  the type for <code>i</code> gets inferred as <code>()</code>.</p>
<p>Any code pointers I can look at to fix the issue?</p>



<a name="174237070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Semicolons%20after%20%60return%60%20spoils%20type%20inference/near/174237070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Semicolons.20after.20.60return.60.20spoils.20type.20inference.html#174237070">(Aug 27 2019 at 14:58)</a>:</h4>
<p>rustc basically notices that the code path diverges and makes its type <code>!</code>. So we'd need to do something similar</p>



<a name="174238710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Semicolons%20after%20%60return%60%20spoils%20type%20inference/near/174238710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Semicolons.20after.20.60return.60.20spoils.20type.20inference.html#174238710">(Aug 27 2019 at 15:16)</a>:</h4>
<p>so that's a bit involved and requires some refactoring since we need to keep track of whether the code path diverges</p>



<a name="174242957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Semicolons%20after%20%60return%60%20spoils%20type%20inference/near/174242957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Semicolons.20after.20.60return.60.20spoils.20type.20inference.html#174242957">(Aug 27 2019 at 15:59)</a>:</h4>
<p>Nice, looks like the next thing to work on after Never coercion is merged, thank you.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>